home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / message.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  2KB  |  77 lines

  1. #include "amiga.h"
  2. #include <intuition/intuition.h>
  3. #include <stdarg.h>
  4.  
  5. static struct EasyStruct msg =
  6. {
  7.     sizeof(struct EasyStruct),
  8.     0,
  9.     NULL,
  10.     NULL,
  11.     "Ok",
  12. };
  13.  
  14. static void message(char *format, long *args)
  15. /* Display a message which is as visible as possible (either to the console
  16.    or to as a requester).
  17.    Assume very little about library state */
  18. {
  19.     LONG msg_EasyRequestArgs(struct Window *window, struct EasyStruct *easyStruct,
  20.                  ULONG * idcmpPtr, APTR args);
  21. #pragma libcall msg_IntuitionBase msg_EasyRequestArgs 24C BA9804
  22.     BPTR fh;
  23.     int close = FALSE;
  24.     extern char *_ProgramName;
  25.     extern struct WBStartup *WBenchMsg;
  26.  
  27.     fh = _us->pr_CES;
  28.     if (!fh)
  29.     if (!WBenchMsg && (fh = Open("console:", MODE_OLDFILE)))
  30.         close = TRUE;
  31.  
  32.     if (fh) {
  33.     FPrintf(fh, "%s: ", _ProgramName);
  34.     VFPrintf(fh, format, (long *) args);
  35.     FPutC(fh, '\n');
  36.     if (close)
  37.         Close(fh);
  38.     } else {
  39.     struct Window *win = (struct Window *) _us->pr_WindowPtr;
  40.     if (win != (struct Window *) -1) {
  41.         struct Library *msg_IntuitionBase = OpenLibrary("intuition.library", 37);
  42.  
  43.         if (msg_IntuitionBase) {
  44.         msg.es_Title = _ProgramName;
  45.         msg.es_TextFormat = format;
  46.         msg_EasyRequestArgs(win, &msg, 0, args);
  47.         CloseLibrary(msg_IntuitionBase);
  48.         }
  49.     }
  50.     }
  51. }
  52.  
  53. void _message(char *format,...)
  54. /* Display a message which is as visible as possible (either to the console
  55.    or to as a requester).
  56.    Assume very little about library state */
  57. {
  58.     va_list args;
  59.  
  60.     va_start(args, format);
  61.     message(format, (long *) args);
  62. }
  63.  
  64. void _fail(char *format,...)
  65. /* Display a message which is as visible as possible (either to the console
  66.    or to as a requester).
  67.    Assume very little about library state.
  68.    Exit with error code RETURN_FAIL after that. */
  69. {
  70.     va_list args;
  71.  
  72.     va_start(args, format);
  73.     message(format, (long *) args);
  74.  
  75.     exit(RETURN_FAIL);        /* The library should always be cleanup-able */
  76. }
  77.